<%@ page contentType="text/html;charset=UTF-8" isErrorPage="true"%>
<%@ include file="/comm/include.jsp"%>
<script type="text/javascript">
$(function(){
	$('#data').datagrid({  
	    url:'${ctx}/merchant/list.htm',
	    pagination:true,
	    checkOnSelect:false,
	    singleSelect:true,
	    idField:'id',
	    nowrap:true,
	    rownumbers:true,
	    columns:[[
	        {field:'name',title:'商户名称',width:150},
	        {field:'noticeList',title:'注意事项',hidden:true,width:350},
	        {field:'website',title:'官方网站'},
	        {field:'serviceLine',title:'服务热线',width:150},
	        {field:'intro',title:'商户简介',width:500},
	        {field:'opt',title:'返利比率设置',width:100,align:'center',
				formatter: function(value,row,index){
					return '<img src="${ctx}/style/icons/page_white_star.png" onclick="addDetail('+row.id +',\''+row.name+'\')">&nbsp;'+
						   '<img src="${ctx}/style/icons/page_white_paintbrush.png" onclick="listDetail('+row.id +',\''+row.name+'\')">';
				}	
			}
	    ]],
	    toolbar:"#tb",
	    onDblClickRow:function(rowIndex, rowData){
	    	$('#content').html(rowData.intro);
            $('#showDetail').dialog('open').dialog('setTitle',rowData.name);
		}
	});
	
	$("#addMerchant").click(function(){
		window.location.href="${ctx}/merchant/add.htm";
	});
	$("#editMerchant").click(function(){
		var row = $('#data').datagrid('getSelected');
        if (row){
			window.location.href= "${ctx}/merchant/edit.htm?id=" + row.id;
        }
	});
	$("#removeMerchant").click(function(){
		var row = $('#data').datagrid('getSelected');
        if (row){
        	$.post('${ctx}/merchant/remove.htm?id='+row.id,function(data){
    			if(data==1) {
    				$('#data').datagrid('reload');
    			}else {
    				alert('删除失败');
    			}
    		},"text");
        }
	});
	
	$("#rebateDetail").click(function(){
		var row = $('#data').datagrid('getSelected');
        if (row){
        	$('#content').html(row.intro);
            $('#showDetail').dialog('open').dialog('setTitle',row.name);
        }
	});
});
function listDetail(merchantId,name) {
	parent.show('',"${ctx}/rebatedetail/list.htm?merchantId=" + merchantId);
}
function addDetail(merchantId,name) {
	parent.show('',"${ctx}/rebatedetail/add.htm?merchantId=" + merchantId);
}
</script>
<div>
	<table id="data"></table>
	<div id="tb" style="padding:5px;height:auto">
		<div>
			<a href="javascript:;" id="rebateDetail" class="easyui-linkbutton" iconCls="icon-detail-sn" plain="true">返利详情</a> 
			<a href="javascript:;" id="addMerchant" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加商户</a> 
			<a href="javascript:;" id="editMerchant" class="easyui-linkbutton" iconCls="icon-edit-sn" plain="true">修改商户</a> 
			<a href="javascript:;" id="removeMerchant" class="easyui-linkbutton" iconCls="icon-del-sn" plain="true">删除商户</a> 
		</div>
	</div>
	<div id="showDetail" class="easyui-dialog" data-options="closed:true,maximizable:true" style="width:500px;height:380px;padding:5px">
            <div id="content"></div>
     </div>
</div>


